/****************************************************
	文件：ResUtil.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/9/27 20:0:33
	功能：资源加载工具类
*****************************************************/

using System;
using UnityEngine;
using HTUtility;

namespace HTFramework.ResKit
{
    public class ResUtil
    {
        #region Public Function
        /// <summary>
        /// 获取指定AB包的完整路径
        /// </summary>
        public static string GetABFullPath(string abName)
        {
            return Application.streamingAssetsPath + "/AssetBundles/" + GetPlatformName() + "/" + abName;
        }
        /// <summary>
        /// 获取当前平台Name
        /// </summary>
		public static string GetPlatformName()
        {
#if UNITY_EDITOR
            return GetPlatformName(UnityEditor.EditorUserBuildSettings.activeBuildTarget);
#else
            return GetPlatformName(Application.platform);
#endif
        }
        #endregion


        #region Private Function
#if UNITY_EDITOR
        private static string GetPlatformName(UnityEditor.BuildTarget buildTarget)
        {
            switch (buildTarget)
            {
                case UnityEditor.BuildTarget.StandaloneWindows:
                case UnityEditor.BuildTarget.StandaloneWindows64:
                    return FConsts.PlatformName.Windows;
                case UnityEditor.BuildTarget.iOS:
                    return FConsts.PlatformName.iOS;
                case UnityEditor.BuildTarget.Android:
                    return FConsts.PlatformName.Android;
                case UnityEditor.BuildTarget.StandaloneLinux:
                case UnityEditor.BuildTarget.StandaloneLinux64:
                case UnityEditor.BuildTarget.StandaloneLinuxUniversal:
                    return FConsts.PlatformName.Linux;
                case UnityEditor.BuildTarget.StandaloneOSX:
                    return FConsts.PlatformName.OSX;
                case UnityEditor.BuildTarget.WebGL:
                    return FConsts.PlatformName.WebGL;
                default:
                    return null;
            }
        }
#endif
        private static string GetPlatformName(RuntimePlatform runtimePlatform)
        {
            switch (runtimePlatform)
            {
                case RuntimePlatform.WindowsPlayer:
                    return FConsts.PlatformName.Windows;
                case RuntimePlatform.IPhonePlayer:
                    return FConsts.PlatformName.iOS;
                case RuntimePlatform.Android:
                    return FConsts.PlatformName.Android;
                case RuntimePlatform.LinuxPlayer:
                    return FConsts.PlatformName.Linux;
                case RuntimePlatform.OSXPlayer:
                    return FConsts.PlatformName.OSX;
                case RuntimePlatform.WebGLPlayer:
                    return FConsts.PlatformName.WebGL;
                default:
                    return null;
            }
        }
        #endregion
    }
}
